package service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import pojo.Customer;
import service.CustomerManager;

public class CustomerManagerImpl implements CustomerManager {
	private List<Customer> customers=new ArrayList<Customer>();
	public CustomerManagerImpl() {
		Customer c1=new Customer(UUID.randomUUID().toString(), "JohnYu", 23.45, true, new Date());
		Customer c2=new Customer(UUID.randomUUID().toString(), "AliceLi", 123.45, false, new Date());
		customers.add(c1);
		customers.add(c2);
	}
	
	
	@Override
	public Customer addCustomer(Customer c) {
		synchronized (customers) {
			c.setId(UUID.randomUUID().toString());
			customers.add(c);
		}
		return c;
	}
	@Override
	public Customer updateCustomer(Customer c) {
		synchronized (customers) {
			int index=customers.indexOf(c);
			customers.set(index, c);
		}
		return c;
	}
	@Override
	public List<Customer> findAllCustomers() {
		return customers;
	}

	@Override
	public String deleteCustomer(String id) {
		synchronized (customers) {
			Customer c=new Customer();
			c.setId(id);
			customers.remove(c);
		}
		return "{}";
	}

}
